package com.gitee.wsl.ext.number

import kotlin.math.abs
import kotlin.math.sign


/** Moves from toward to by the delta value.
 *  Use a negative delta value to move away. */
fun moveToward(from: Int, to: Int, delta: Int) = if (abs(to - from) <= delta) to else from + (to - from).sign * delta

/** Moves from toward to by the delta value.
 *  Use a negative delta value to move away. */
fun moveToward(from: Long, to: Long, delta: Long) = if (abs(to - from) <= delta) to else from + (to - from).sign * delta

/** Moves from toward to by the delta value.
 *  Use a negative delta value to move away. */
fun moveToward(from: Float, to: Float, delta: Float) = if (abs(to - from) <= delta) to else from + (to - from).sign * delta

/** Moves from toward to by the delta value.
 *  Use a negative delta value to move away. */
fun moveToward(from: Double, to: Double, delta: Double) = if (abs(to - from) <= delta) to else from + (to - from).sign * delta
